//index.js
//获取应用实例
const app = getApp();
var devArr = [];
var util = require('../../utils/util.js');
const log = require('../../utils/log.js');
var timeStorage = require('../../utils/shixiaoxing-Storage.js');
Page({
  data: {
    topSrc: '',
    userInfo: {},
    hasUserInfo: false,
    isLog: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    province: '--',
    city: '--',
    district: '--',
    latitude: '',
    longitude: '',
    weather: '--',//空气情况
    quality: "--",
    pm2_5: "--",
    temperature: "--",
    wifiList: [],
    isAdd: false, //是否有用户绑定的设备
    devImg: '../../images/logo.png', //设备图标
    IMEI: '',//二维码中获取IMEI
    devStatus: [{  //设备信息
      devName: '空气净化器',//设备名称
      online: 1,//设备是否在线
      onlineTxt: '在线',//设备是否在线
      modelId: 'ujthjf',//设备型号
      did: '110000001000002020', //设备id
      isTouch: false,//是否滑动
     }],//[{  //设备信息
    //   devName: '空气净化器',//设备名称
    //   online: 1,//设备是否在线
    //   onlineTxt: '在线',//设备是否在线
    //   modelId: 'ujthjf',//设备型号
    //   did: '110000001000002020', //设备id
    //   isTouch: false,//是否滑动
    // }]
    isedit: false, //是否编辑名称，用于编辑弹框显示
    inputVal: '空气净化器', //编辑获取当前名称
    curDevId: '', //选中当前设备Id
    isdel: false, //删除设备弹框
    ishost: false, //是否主人权限
    devUser: [],//设备所属用户列表除了当前用户外 参数telephone,nickname,host,uid
    curhost: false,//当前用户主人客人
    isHostList: false,//转让用户列表弹框
    curName: '', //获取当前设备名称
    // isTouch:true, //是否滑动
    isShouquan: true, //是否地理授权 默认已授权
    numTime: 0, //计时
    startX: 0,
    startY: 0,
    isTip: true,//未登录提示
  },
  onLoad: function () {
    //判断onLaunch是否执行完毕
    var that = this;
    // app.userLogin().then((res) => {
    //   //数据请求成功之后的操作
    //   //可以请求其他的数据了
    //   console.log(res);
    // }, (error) => {
    //   console.log('数据请求失败：' + error)
    // })
    //获得dialog组件
    // that.dialog = that.selectComponent("#dialog");
    // 获取手机系统
    log.info('打一些日志测试一下');
    log.setFilterMsg('filterkeyword');
    that.getUserLocation();
    devArr = [];
    try {
      app.globalData.isLogin = wx.getStorageSync('isLogin');
      app.globalData.openKey = wx.getStorageSync('openKey');
      app.globalData.openId = wx.getStorageSync('openId');
      app.globalData.openIdPay = wx.getStorageSync('openIdPay');
      app.globalData.unionid = wx.getStorageSync('unionid');
    } catch (e) {
      // Do something when catch error
    }
    if (app.globalData.isLogin==true) {
      that.setData({
        isLog: app.globalData.isLogin,
        isTip: false
      })
      console.log(app.globalData.isLogin);
      that.devListFun();
    } else {
      //登陆成功后自己希望执行的，和上面一样
      that.setData({
        devStatus: [],
        isLog: app.globalData.isLogin,
        isTip: true
      })
    }
  },
  onShow: function () {
    var that = this;
    try {
      app.globalData.isLogin = wx.getStorageSync('isLogin');
      app.globalData.openKey = wx.getStorageSync('openKey');
      app.globalData.openId = wx.getStorageSync('openId');
      app.globalData.openIdPay = wx.getStorageSync('openIdPay');
      app.globalData.unionid = wx.getStorageSync('unionid');
      console.log("openKey:" + app.globalData.isLogin)
    } catch (e) {
      // Do something when catch error
    }
    that.setData({
      isLog: app.globalData.isLogin
    })
    console.log("isLog:" + that.data.isLog);
    if (app.globalData.isLogin==true) { //是否登录
      var devVar=wx.getStorageSync('devStatus')
      if (devVar){
        that.setData({
          devStatus: devVar,
        })
      }
      that.setData({
        isTip: false
      })
      that.devListFun(); 
    }else{
      that.setData({
        isTip: true
      })
    }
  },
  onHide: function () {
    log.info('在onHide打一些日志测试一下')
  },
  onReady: function () {

  },
  showDialog: function () {
    this.dialog.showDialog();
  },
  confirmEvent: function () {
    this.getUserInfo();
    this.dialog.hideDialog();
  },
  bindGetUserInfo: function () {
    // 用户点击授权后，这里可以做一些登陆操作
    this.getUserLocation();
  },
  // 授权获取地理位置
  getUserLocation: function () {
    let vm = this;
    wx.getSetting({
      success: (res) => {
        console.log(JSON.stringify(res));
        // res.authSetting['scope.userLocation'] == undefined    表示 初始化进入该页面
        // res.authSetting['scope.userLocation'] == false    表示 非初始化进入该页面,且未授权
        // res.authSetting['scope.userLocation'] == true    表示 地理位置授权
        // 拒绝授权后再次进入重新授权 res.authSetting['scope.userLocation'] != undefined &&
        console.log(res.authSetting['scope.userLocation'])
        if (res.authSetting['scope.userLocation'] == false) {
          console.log('authSetting:status:拒绝授权后再次进入重新授权', res.authSetting['scope.userLocation'])
          wx.showModal({
            title: '',
            content: '为了更好的为您服务,【壁挂炉】需要获取你的地理位置，请确认授权',
            success: function (res) {
              if (res.confirm) {
                wx.openSetting({
                  success: function (dataAu) {
                    // console.log('dataAu:success', dataAu)
                    if (dataAu.authSetting["scope.userLocation"] == true) {
                      //再次授权，调用wx.getLocation的API
                      vm.getLocation(dataAu);
                      app.globalData.isUserLocation=true;
                    } else {
                      app.globalData.isUserLocation=false;
                    }
                  }
                })
              }
            }
          })

        }// 初始化进入，未授权
        else if (res.authSetting['scope.userLocation'] == undefined) {
          // console.log('authSetting:status:初始化进入，未授权', res.authSetting['scope.userLocation'])
          //调用wx.getLocation的API
          app.globalData.isUserLocation = false;
          vm.getLocation(res);
        }
        // 已授权
        else if (res.authSetting['scope.userLocation']) {
          // console.log('authSetting:status:已授权', res.authSetting['scope.userLocation'])
          //调用wx.getLocation的API
          app.globalData.isUserLocation = true;
          vm.getLocation(res);
        }
      }
    })
  },
  // 微信获得经纬度
  getLocation: function (userLocation) {
    let that = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        console.log(JSON.stringify(res))
        var latitude = res.latitude;
        var longitude = res.longitude;
        var num = timeStorage.getStorageSyncTime('timer');
        console.log(num);
        if (num) {
          wx.getStorage({
            key: 'weather',
            success(res) {
              console.log(res.data);
              var d = JSON.parse(res.data)
              that.setData({
                weather: d.weather,
                quality: d.quality,
                pm2_5: d.pm2_5,
                temperature: d.temperature,
                province: d.province,
                city: d.city,
                district: d.district,
              })
            }
          })
        }
        else {
          timeStorage.setStorageSyncHour('timer', 1, 12);
          that.weatherFun(latitude, longitude)
        }
      },
      fail: function (res) {
        // console.log('getLocation:fail', res)
        if (res.errMsg === 'getLocation:fail:auth denied') {
          // wx.showToast({
          //   title: '拒绝授权',
          //   icon: 'none'
          // })
          return
        }
        if (!userLocation || !userLocation.authSetting['scope.userLocation']) {
          that.getUserLocation();
        } else if (userLocation.authSetting['scope.userLocation']) {
          wx.showModal({
            title: '',
            content: '请在系统设置中打开定位服务',
            showCancel: false,
            success: result => {
              // if (result.confirm) {
              //   wx.navigateBack()
              // }
            }
          })
        } else {
          wx.showToast({
            title: '授权失败',
            icon: 'none'
          })
        }
      }
    })
  },
  // 获取当前天气信息等
  weatherFun: function (latitude, longitude) {
    var vm = this;
    console.log("获取天气接口")
    wx.request({
      url: 'https://ali-weather.showapi.com/gps-to-weather',
      data: {
        'from': 5,
        'lat': latitude,
        'lng': longitude,
        'need3HourForcast': 0,
        'needAlarm': 0,
        'needHourData': 0,
        'needIndex': 0,
        'needMoreDay': 0
      },
      header: {
        'content-type': 'application/json', // 默认值
        "Authorization": "APPCODE " + app.globalData.APPCODE
      },
      success(res) {
        console.log(res)
        vm.setData({
          weather: res.data.showapi_res_body.now.weather,
          quality: res.data.showapi_res_body.now.aqiDetail.quality,
          pm2_5: res.data.showapi_res_body.now.aqiDetail.pm2_5,
          temperature: res.data.showapi_res_body.now.temperature,
          province: res.data.showapi_res_body.cityInfo.c7,
          city: res.data.showapi_res_body.cityInfo.c5,
          district: res.data.showapi_res_body.cityInfo.c3,
        })
        // 天气数据缓存
        var wParam = {
          'weather': res.data.showapi_res_body.now.weather,
          'quality': res.data.showapi_res_body.now.aqiDetail.quality,
          'pm2_5': res.data.showapi_res_body.now.aqiDetail.pm2_5,
          'temperature': res.data.showapi_res_body.now.temperature,
          'province': res.data.showapi_res_body.cityInfo.c7,
          'city': res.data.showapi_res_body.cityInfo.c5,
          'district': res.data.showapi_res_body.cityInfo.c3,
        }
        wx.setStorage({
          key: "weather",
          data: JSON.stringify(wParam)
        })
      }
    })
  },
  getUserInfo: function (e) {
    // app.globalData.userInfo = e.detail.userInfo
    // this.setData({
    //   userInfo: e.detail.userInfo,
    //   hasUserInfo: true
    // })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        console.log(res.authSetting);
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          console.log(res.authSetting['scope.userInfo']);
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              console.log(res.userInfo)
              app.globalData.userInfo = res.userInfo
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              this.setData({
                userInfo: res.userInfo,
                hasUserInfo: true
              })
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            },
            fail: function (err) {
              console.log(err)
            }
          })
        }
      }
    })
  },
  // 获取设备列表
  devListFun() {
    var that = this;
    var timestamp = new Date().getTime();
    console.log("openKey:" + app.globalData.openKey);
    // 查询用户绑定的设备列表以及分组信息
    wx.request({
      url: 'https://papi.zcyun.cn/v1/user/devices',
      method: "GET",
      data: {},
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("GET" + '/v1/user/devices' + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          devArr = [];
          that.setData({
            devStatus: [],
          })
          var arrDev = res.data.data.devs;
          console.log(res.data.data.devs);
          for (var i = 0; i < arrDev.length; i++) {
            // if (arrDev[i].modelId == app.globalData.modeId) {
              var onlineTxt = '';
              if (arrDev[i].online == 1) {
                onlineTxt = '在线'
              } else {
                onlineTxt = '离线'
              }
              var dev = {
                devName: arrDev[i].name,
                online: arrDev[i].online,
                onlineTxt: onlineTxt,
                modelId: arrDev[i].modelId,
                did: arrDev[i].did,
                isTouch: false
              }
              devArr.push(dev);
              // that.globalData.deviceId = arrDev[i].did;
            // }
          }
          that.setData({
            devStatus: devArr
          })
          wx.setStorage({
            key: 'devStatus',
            data: that.data.devStatus,
          })
          console.log(that.data.devStatus)
          if (that.data.devStatus.length > 0) {
            that.setData({
              isAdd: true,
            })
          } else {
            that.setData({
              isAdd: false
            })
          }
        } else {
          app.globalData.isLogin = false;
          that.setData({
            isLog: app.globalData.isLogin
          })
          // var data1 = [{ "openId": '' }, { "openKey": '' }, { "isLogin": false }]
          // wx.setStorage("keyData", data1);
          wx.setStorage({
            key: 'openId',
            data: '',
            success: function (res) {
              console.log('异步保存成功')
            }
          })
          wx.setStorage({
            key: 'openKey',
            data: '',
            success: function (res) {
              console.log('异步保存成功')
            }
          })
          wx.setStorage({
            key: 'isLogin',
            data: 'false',
            success: function (res) {
              console.log('异步保存成功')
            }
          })
        }
      }
    })
  },
  // 2G/NB扫码
  scanMode: function () {
    var that = this;
    var showImei;
    wx.scanCode({
      success: (res) => {
        console.log(res);
        showImei = res.result;
        if (res.result.indexOf('/') > 0) {
          var tempAdd = showImei.split("/");
          var tempImei = tempAdd[tempAdd.length - 1]
          that.setData({
            IMEI: tempImei.split(";")[0]
          })
        } else {
          showImei.split(";");
          that.setData({
            IMEI: res.result.split(";")[0]
          })
        }
        console.log(that.data.IMEI);
        // GPRS模块绑定
        var timestamp = new Date().getTime();
        wx.request({
          url: 'https://papi.zcyun.cn/v1/user/device/bind/mac/' + that.data.IMEI,
          data: {
          },
          method: "GET",
          header: {
            'content-type': 'application/json', // 默认值
            'openId': app.globalData.openId,
            'ts': timestamp,
            'sign': util.sha1("GET" + '/v1/user/device/bind/mac/' + that.data.IMEI + timestamp + app.globalData.openKey)
          },
          success(res) {
            console.log(res.data);
            if (res.data.code == 0 || res.data.code == 20129) {
              // 重新获取设备列表
              if (res.data.code == 20129) {
                wx.showToast({
                  title: '设备已绑定',
                  icon: "none",
                  duration: 2000
                })
                setTimeout(function () {
                  wx.hideToast();
                  clearTimeout();
                }, 2000)
              }
              that.devListFun();
            } else {
              wx.showToast({
                title: '绑定设备不成功',
                icon: "none",
                duration: 2000
              })
              setTimeout(function () {
                wx.hideToast();
                clearTimeout();
              }, 2000)
            }
          }
        })
      },
      fail: (res) => {},
      complete: (res) => {
      }
    })
  },
  //添加设备按键
  addDevice: function () {
    if (app.globalData.isLogin) {
      // 扫码
      this.scanMode();
    } else {
      wx.switchTab({
        url: '../me/index/index'
      })
    }
  },
  mytouchstart: function (e) {  //记录触屏开始时间
    // this.setData({ start: e.timeStamp })
    // 获得起始坐标
    // this.startX = e.touches[0].clientX;
    // this.startY = e.touches[0].clientY;
    this.data.devStatus.forEach(function (v, i) {
      if (v.isTouch)//只操作为true的
        v.isTouch = false;
    })
    this.setData({
      startX: e.touches[0].clientX,
      startY: e.touches[0].clientY,
      devStatus: this.data.devStatus
    })
  },
  //滑动事件处理
  mytouchmove: function (e) {
    var that = this,
      index = e.currentTarget.dataset.index,//当前索引
      startX = that.data.startX,//开始X坐标
      startY = that.data.startY,//开始Y坐标
      touchMoveX = e.changedTouches[0].clientX,//滑动变化坐标
      touchMoveY = e.changedTouches[0].clientY,//滑动变化坐标
      //获取滑动角度
      angle = that.angle({ X: startX, Y: startY }, { X: touchMoveX, Y: touchMoveY });
    that.data.devStatus.forEach(function (v, i) {
      v.isTouch = false
      //滑动超过30度角 return
      if (Math.abs(angle) > 30) return;
      if (i == index) {
        if (touchMoveX > startX) //右滑
          v.isTouch = false
        else //左滑
          v.isTouch = true
      }
    })
    //更新数据
    that.setData({
      devStatus: that.data.devStatus,
      inputVal: that.data.devStatus[index].devName,
      curDevId: that.data.devStatus[index].did,
      curName: that.data.devStatus[index].devName,
    })
  },
  /**
  * 计算滑动角度
  * @param {Object} start 起点坐标
  * @param {Object} end 终点坐标
  */
  angle: function (start, end) {
    var dX = end.X - start.X,
      dY = end.Y - start.Y
    //返回角度 /Math.atan()返回数字的反正切值
    return 360 * Math.atan(dY / dX) / (2 * Math.PI);
  },
  //单击进入详情界面
  devBtn: function (e) {
    var that = this;
    console.log(e.currentTarget.dataset['index']);
    //单击事件内容
    var ind = e.currentTarget.dataset['index'];
    that.setData({
      inputVal: that.data.devStatus[ind].devName,
      curDevId: that.data.devStatus[ind].did,
      curName: that.data.devStatus[ind].devName,
    })
    // if (that.data.devStatus[ind].online == 1) {
    wx.navigateTo({
      url: '../deviceControl/deviceControl?deviceId=' + that.data.devStatus[ind].did + "&curname=" + that.data.devStatus[ind].devName + "&online=" + that.data.devStatus[ind].online,
    })
    // } else {
    //   wx.showModal({
    //     title: '设备处于离线状态',
    //     content: '请检查：1.设备是否离线；2.设备WiFi网络连接是否正常;3.可尝试将设备断电后重新启动',
    //     cancelColor: '#3486ff',
    //     showCancel: false,
    //     confirmText: '我知道了'
    //   })
    // }
  },
  // 编辑名称
  editNameFun: function (e) {
    var that = this;
    that.setData({
      isedit: true,
    })
    var index = e.currentTarget.dataset['index'];
    var list = that.data.devStatus;
    list[index].isTouch = false;
    that.setData({
      devStatus: list
    })
  },
  //名称编辑弹框取消
  cancel: function () {
    this.setData({
      isedit: false,
      inputVal: '',
      isdel: false
    })

  },
  //名称编辑弹框确认
  editconfirm: function () {
    var that = this;
    if (that.data.inputVal == '') {
      wx.showToast({
        title: '请输入名称',
        icon: none
      })
      return true
    }
    var timestamp = new Date().getTime();
    console.log("openKey:" + app.globalData.openKey);
    console.log("zcyAppID:" + app.globalData.zcyAppID)
    var param = {
      "name": that.data.inputVal
    }
    var params = JSON.stringify(param);
    wx.request({
      url: 'https://papi.zcyun.cn/v1/device/' + that.data.curDevId,
      method: "PUT",
      data: {
        "name": that.data.inputVal
      },
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("PUT" + '/v1/device/' + that.data.curDevId + params + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          // 重新获取设备列表
          that.devListFun();
        }
      }
    })
    this.setData({
      isedit: false,
      inputVal: ''
    })
  },
  //清空输入内容
  delInput: function () {
    this.setData({
      inputVal: ''
    })
  },
  //输入名称
  nameInput: function (e) {
    this.setData({
      inputVal: e.detail.value
    })
  },
  // 删除设备
  delDevFun: function (e) {
    var timestamp = new Date().getTime();
    var that = this;
    var index = e.currentTarget.dataset['index'];
    var list = that.data.devStatus;
    list[index].isTouch = false;
    that.setData({
      curhost: 0,
      devStatus: list
    })
    // 设备所属的用户列表
    wx.request({
      url: 'https://papi.zcyun.cn/v1/user/device/users/' + that.data.curDevId,
      method: "GET",
      data: {
        "deviceId": that.data.curDevId
      },
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("GET" + '/v1/user/device/users/' + that.data.curDevId + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          var userArr = res.data.data;
          var useList = [];
          for (var i = 0; i < userArr.length; i++) {
            if (userArr[i].telephone == app.globalData.telephone) {
              that.setData({
                curhost: userArr[i].host
              })
            } else {
              var usetemp = {
                telephone: userArr[i].telephone,
                nickname: userArr[i].nickname,
                host: userArr[i].host,
                uid: userArr[i].uid
              }
              useList.push(usetemp);
            }
          }
          that.setData({
            devUser: useList,
          })
          console.log("设备所属列表：" + JSON.stringify(that.data.devUser));
          console.log("登录电话：" + app.globalData.telephone);
          if (that.data.devUser.length > 0) {
            if (that.data.curhost == 1) {
              that.setData({
                ishost: true,
              })
            } else {
              that.setData({
                ishost: false,
              })
            }
          } else {
            that.setData({
              ishost: false,
            })
          }
        }
      }
    })

    this.setData({
      isdel: true
    })
  },
  //删除设备弹框确认
  delconfirm: function () {
    var that = this;
    var timestamp = new Date().getTime();
    var param = {
      "did": that.data.curDevId
    }
    var params = JSON.stringify(param);
    // 用户解绑设备
    wx.request({
      url: 'https://papi.zcyun.cn/v1/user/device/unbind/' + that.data.curDevId,
      method: "POST",
      data: {
        "did": that.data.curDevId
      },
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("POST" + '/v1/user/device/unbind/' + that.data.curDevId + params + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          // 重新获取设备列表
          that.devListFun();
        }
      }
    })
    that.setData({
      isdel: false
    })
  },
  //去转让
  zhuanrang: function () {
    this.setData({
      isHostList: true,
      isdel: false
    })
  },
  // 转让给其他用户
  hostBtn: function (e) {
    var that = this;
    var index = e.currentTarget.dataset['index'];
    var timestamp = new Date().getTime();
    console.log(that.data.devUser[index].uid);
    console.log("当前设备ID：" + that.data.curDevId)
    // 转让主人权限
    // 用户解绑设备
    var param = {
      "host": that.data.devUser[index].uid,
      "did": that.data.curDevId
    }
    var params = JSON.stringify(param);
    wx.request({
      url: 'https://papi.zcyun.cn/v1/user/device/unbind/' + that.data.curDevId,
      method: "POST",
      data: {
        "host": that.data.devUser[index].uid,
        "did": that.data.curDevId
      },
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("POST" + '/v1/user/device/unbind/' + that.data.curDevId + params + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          // 重新获取设备列表
          that.devListFun();
        }
      }
    })
    this.setData({
      isHostList: false
    })
  },
  // 共享给家人
  shareFun: function (e) {
    var that = this;
    var index = e.currentTarget.dataset['index'];
    var list = that.data.devStatus;
    list[index].isTouch = false;
    that.setData({
      devStatus: list
    })
    var timestamp = new Date().getTime();
    var param = {
      "did": that.data.curDevId
    }
    var params = JSON.stringify(param);
    wx.request({
      url: 'https://papi.zcyun.cn/v1/user/device/share/' + that.data.curDevId,
      method: "GET",
      data: {
        "did": that.data.curDevId
      },
      header: {
        'content-type': 'application/json', // 默认值
        'openId': app.globalData.openId,
        'ts': timestamp,
        'sign': util.sha1("GET" + '/v1/user/device/share/' + that.data.curDevId + timestamp + app.globalData.openKey)
      },
      success(res) {
        console.log(res.data);
        if (res.data.code == 0) {
          wx.navigateTo({
            url: '../shareQR/shareQR?sk=' + res.data.sk + '&devName=' + that.data.curName,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
          })
        }
      }
    })
  },
  loginCel: function(){
    this.setData({
      isTip: false
    })
  },
  loginBtn: function(e){
    wx.switchTab({
      url: '../me/index/index'
    })
  }
})
